﻿using System;
using System.Linq.Expressions;
using System.Reflection;
using Basmus.Conel;
using Basmus.Util;

namespace Basmus.Values.Attributive
{
    public static class BinderExtension
    {
        public static Binding Bind(this IBinder bindingService, PropertyInfo propertyInfo)
        {
            var binding = bindingService.Bind(propertyInfo.PropertyType);
            return binding;
        }

        public static Binding Bind(this IBinder bindingService, PropertyInfo propertyInfo, Type elementType)
        {
            var binding = bindingService.Bind(propertyInfo.PropertyType, elementType);
            return binding;
        }

        public static Binding Bind<T, TProperty>(this IBinder bindingService, Expression<Func<T, TProperty>> propertyExpression)
        {
            var propertyInfo = propertyExpression.GetPropertyInfo();
            var binding = bindingService.Bind(propertyInfo);
            return binding;
        }

        public static Binding Bind<T, TProperty>(this IBinder bindingService, Expression<Func<T, TProperty>> propertyExpression, Type elementType)
        {
            var propertyInfo = propertyExpression.GetPropertyInfo();
            var binding = bindingService.Bind(propertyInfo, elementType);
            return binding;
        }
    }
}
